"""
需求
1现在有省，市，县3级结构，要求程序启动后，允许用户可依次选择进入各级子菜单
2可以在任意一级菜单返回上一级
3可以在任意一级菜单退出程序

"""
menu ={
    "广东省":{
        "珠海市":{
            "香洲区":["香洲一区","香洲五区","香洲十区"],
            "斗门区":["斗门一区","斗门五区","斗门十区"],
            "金湾区":["金湾一区","金湾五区","金湾十区"]
        },
        "广州市":{
            "天河区":["天河一区","天河五区","天河十区"],
            "番禺区":["香洲一区","香洲五区","香洲十区"],
            "花都区":["香洲一区","香洲五区","香洲十区"]
        },
        "深圳市":{
            "罗湖区":["罗湖一区","罗湖五区","罗湖十区"],
            "福田区":["福田一区","福田五区","福田十区"],
            "南山区":["南山一区","南山五区","南山十区"]
        }
    },
    "陕西省":{
        "西安市":{
            "新城区",
            "未央区",
            "雁塔区"
        },
        "咸阳市":{
            "秦都区",
            "杨陵区",
            "渭城区"
        },
        "宝鸡市":{
            "渭滨区",
            "金台区",
            "陈仓区"
        }
    },
    "四川省":{
        "成都市":{
            "锦江区",
            "青羊区",
            "金牛区"
        },
        "自贡市":{
            "自流井区",
            "贡井区",
            "大安区"
        },
        "德阳市":{
            "中江县",
            "罗江县",
            "广汉市"
        }
    }
}



# print("＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝多级菜单＝＝＝＝＝＝＝＝＝＝＝＝＝")
# q_flag = True
# while q_flag:
#     print(("省".center(50,"=")))
#     for i in menu:
#         print(i)
#     province1 = input("请输入要查到的省：")
#     if province1 in menu:
#         while q_flag:
#             print("市".center(50,"="))
#             for i2 in menu[province1]:
#                 print(i2)
#             city = input("请输入要查到的市：")
#             if city in menu[province1]:
#                 while q_flag:
#                     print("区县".center(50,"="))
#                     for  i3 in menu[province1][city]:
#                         print(i3)
#                     county = input("请输入要查找的区县：")
#                     if county in menu[province1][city]:
#                         print(menu[province1][city][county])
#                     elif county == "q":
#                         q_flag = False
#                     elif county == "b":
#                         break
#             elif city == "q":
#                 q_flag = False
#             elif city == "b":
#                 break
#     elif province1 =="q":
#         q_flag = False
#     elif province1 == "b":
#         break


print("＝＝＝＝＝＝＝＝＝＝＝＝＝＝＝多级菜单＝＝＝＝＝＝＝＝＝＝＝＝＝")
q_flag = True
current_layer = menu
# last_layer= [menu]  # 和下面注释的对应
last_layer = []

while q_flag:
    print(("显示当前信息".center(50,"=")))
    for i in current_layer:   #menu[北京]
        print(i)
    choice = input("请输入要进入的菜单：")
    if choice  in current_layer:   #menu[北京]
        if current_layer[choice]:  #进入下一层之前，保存当前层
            last_layer.append(current_layer)   #  #menu[广东省][珠海市]
            current_layer = current_layer[choice]
        else:
            print("当前是最后一页")

    elif choice =="q":
        q_flag = False
    # elif choice == "b":  #和上面的注释的对应
    #     if current_layer:
    #         current_layer = last_layer[-1]
    #         last_layer.pop()
    # else:
    #     print("输入有误，请重新输入：")
    elif choice == "b":
        if len(last_layer)  !=0:
            current_layer = last_layer.pop()
        else:
            print("已经是顶层了")


